package indi.zhifa.recipe.bailan.framework.auth.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import indi.zhifa.recipe.bailan.framework.auth.dao.mapper.DomainMapper;
import indi.zhifa.recipe.bailan.framework.auth.dao.service.IDomainDbService;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.DomainEntity;
import indi.zhifa.recipe.bailan.framework.mysql.entity.annotations.ZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.io.Serializable;

@CacheConfig(cacheNames = "sys_domain")
@ZfDbService(name = "DomainEntity")
public class DomainDbServiceImpl extends ZfDbServiceImpl<DomainMapper, DomainEntity> implements IDomainDbService {

    @Cacheable(key = "#pCode",condition = "#result!=null")
    @Override
    public Long findByCode(String pCode) {
        LambdaQueryWrapper<DomainEntity> queryWrapper = Wrappers.<DomainEntity>lambdaQuery()
                .eq(DomainEntity::getCode,pCode);
        DomainEntity domainEntity = findOne(queryWrapper);
        if(null != domainEntity){
            return domainEntity.getId();
        }else{
            return null;
        }
    }

    @Cacheable(key = "#pId",condition = "#result!=null")
    public DomainEntity check(Serializable pId){
        return super.check(pId);
    }

    @CachePut(key = "#pId")
    public DomainEntity savePull(Long pId,DomainEntity pEntity){
        return super.savePull(pId,pEntity);
    }

    @CachePut(key = "#pId")
    public DomainEntity updatePull(Long pId, DomainEntity pEntity){
        return super.updatePull(pId,pEntity);
    }

    @CacheEvict(key = "#pId")
    public DomainEntity deleteById(Serializable pId){
        return super.deleteById(pId);
    }

}
